#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e6 + 5;

int n, m;
bool np[N];
int primes[N], num, mnp[N], cnt[N];
int d[N];
int b[10];
void init(int n) {
  np[1] = 1;
  rep(i, 2, n) {
    if (!np[i]) primes[++num] = i, mnp[i] = i;
    rep(j, 1, num) {
      ll k = 1ll * primes[j] * i;
      if (k > n) break;
      np[k] = 1;
      mnp[k] = primes[j];
      if (i % primes[j] == 0) break;
    }
  }
  cnt[1] = 1;
  rep(i, 2, n) {
    int k = 0, x = i;
    while (x % mnp[i] == 0) x /= mnp[i], k++;
    cnt[i] = (k + 1) * cnt[x];
  }
}
void solve() {
  cin >> n;
  init(n);
  rep(i, 1, max(100, n)) {
    int x = i;
    int y = 0;
    while (x) y += x % 10, x /= 10;
    d[i] = y <= 9 ? y : d[y];
    if (i <= n) b[d[i]]++;
  }
  ll ans = 0;
  rep(i, 1, 9) rep(j, 1, 9) {
    int k = d[i * j];
    ans += 1ll * b[i] * b[j] * b[k];
  }
  rep(i, 1, n) ans -= cnt[i];
  cout << ans << endl;
  return;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  t = 1;
  while (t--) solve();
  return 0;
}